#include <string.h>  
#include <stdio.h>  
#include <assert.h>  
#include <math.h>  
#include "dominion.h"  
#include "dominion_helpers.h"  
#include "rngs.h" 

void randomTestSea_hag( struct gameState *pre, int handPos, int p ) {
  int i, r, choice1, choice2, choice3;
  int currentPlayer = whoseTurn(pre);
  struct gameState post;

  memcpy(&post, pre, sizeof(struct gameState));
  SelectStream(2);
  PutSeed(3);  
  
  choice1 = floor(Random()*256);
  choice2 = floor(Random()*256);
  choice3 = floor(Random()*256);

  r = cardEffect(sea_hag, choice1, choice2, choice3, &post, handPos, 0);
  assert( r == 0 );

  for (i = 0; i < pre->numPlayers; i++){
	if (i != currentPlayer){
	  pre->discard[i][pre->discardCount[i]] = pre->deck[i][pre->deckCount[i]--];			    
	  pre->deckCount[i]--;
	  pre->discardCount[i]++;
	  //pre->deck[i][pre->deckCount[i]--] = curse;// This was originally there and not right
	  gainCard(curse, pre, 0, currentPlayer);
	}
  }
  
  discardCard(handPos, currentPlayer, state, 0);


  printf("Checking game state... ");
  assert( memcmp(&post, pre, sizeof(struct gameState)) == 0 ); 
  printf("PASSED!\n");
}  

int main() {
  int i, k, n, handPos, p, numPlayers;

  struct gameState g;

  PutSeed(3);
  SelectStream(2);

  for(n=0; n<2000; n++) {
    for(i=0; i<sizeof(struct gameState); i++) 
      ((char *)&g)[i] = floor(Random()*256);
    
    numPlayers = floor(Random()*MAX_PLAYERS);
    p = floor(Random()*numPlayers);

	g.whoseTurn = p;
    g.deckCount[p] = floor(Random()*MAX_DECK);
    g.discardCount[p] = floor(Random()*MAX_DECK);
    g.handCount[p] = floor(Random()*MAX_HAND);
	for(k=0; k<g.playedCardCount; k++)
		g.playedCards[k] = floor(Random()*MAX_DECK);
    g.numActions = 0;
    g.whoseTurn = p;
    g.numPlayers = numPlayers;
    handPos = floor(Random()*g.handCount[p]);    

    randomTestSea_hag( &g, handPos, p );
  }

  printf("All tests PASSED!\n");
  
  return 0;

}